<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <style>
    * {
      margin: 0;
      padding: 0;
    }
    :root {
      /* 全局变量 --xxx 任意名 当然也可以写局部变量*/
      /* --gradient: linear-gradient(to right, 
      purple,
      red, orange, yellow,green, cyan, blue, purple,
      red, orange, yellow,green, cyan, blue, purple
      ); */
    }
    body {
      
    }
    .wrapper {
      width: 800px;
      /* 让块级元素水平居中 */
      margin: 100px auto;
    }
    .text {
      /* linear-gradient() 类似于 rgb() 渐变*/
      --gradient: linear-gradient(to right, 
      purple,
      red, orange, yellow,green, cyan, blue, purple,
      red, orange, yellow,green, cyan, blue, purple
      );
      /* 使用背景图做渐变 */
      background: var(--gradient);
      background-size: 200%;
      /* 背景图默认重复进行加载的 */
      /* 背景图运动改的是背景位置 */
      background-position: 50% 0;
      /* 剪裁背景，只显示文字区域 */
      /* background-clip: text; */
      /* */
      -webkit-background-clip: text;
      font-family: "Arial Black";
      font-size: 80px;
      /* 让文字颜色透明，不要压盖背景 */
      color: transparent;
    }
    /* 表单被选中后，兄弟 p 运动 */
    .btn:checked ~ .text {
      animation: positionChange 2s linear infinite;
    }
    .btn:checked ~ label {
      background-color: #f00;
    }

    .box {
      position: relative;
      left: 0; 
      width: 100px;
      height: 100px;
      padding-left: 3px;
      border: 10px dashed #f00;
      background-clip: content-box;  /* content-box padding-box  border-box*/
     
      background-image: linear-gradient(to right,green, orange 40%, pink);
      animation: move 2s ease infinite;
    }
    /* 定义动画规则 */
    @keyframes move {
      from {
        left: 0;
      }
      to {
        left: 500px;
      }
    }
    /* 定义文字背景位置改变的动画规则 */
    @keyframes positionChange {
      0% {
        background-position-x: 0%;
      }
      100% {
        background-position-x: 100%;
      }
      /* 注释快捷键 Ctrl+/ */
    }
  </style>
</head>
<body>
  <div class="wrapper">
    <input type="checkbox" id="button" class="btn">
    <label for="button">Animate it!</label>
    <p class="text">Hello world</p>
  </div>
  <div class="box"></div>
</body>
</html>